package com.rk.jarjuggler.gui;

import javax.swing.*;
import javax.swing.tree.TreeNode;

import com.intellij.util.ui.ColumnInfo;
import com.intellij.util.ui.treetable.ListTreeTableModelOnColumns;
import com.intellij.util.ui.treetable.TreeTableModel;
import com.rk.jarjuggler.model.DirNode;
import com.rk.jarjuggler.model.LibNode;

public class DirNodeTreeTableModel extends ListTreeTableModelOnColumns implements TreeTableModel {

    static final ColumnInfo[] columnInfos = new ColumnInfo[] {
            new ColumnInfo<DirNode, Object>("Placeholder") {
                public Object valueOf(DirNode object) {
                    return object.getName();
                }
            },
//            new ColumnInfo<DirNode, Object>("Name") {
//                public Object valueOf(DirNode object) {
//                    return object.getName();
//                }
//
//                public int getWidth(JTable table) {
//                    return 200;
//                }
//            },
//            new ColumnInfo<DirNode, Object>("URL") {
//                public Object valueOf(DirNode object) {
//                    return object.getUrl();
//                }
//
//                public int getWidth(JTable table) {
//                    return 400;
//                }
//            },
            new ColumnInfo<DirNode, Object>("Jar") {
                public Object valueOf(DirNode object) {
                    if (object instanceof LibNode) {
                        return ((LibNode)object).hasJar() ? "Y" : null;
                    } else {
                        return null;
                    }
                }

                public int getWidth(JTable table) {
                    return 50;
                }
            },
            new ColumnInfo<DirNode, Object>("Src") {
                public Object valueOf(DirNode object) {
                    if (object instanceof LibNode) {
                        return ((LibNode)object).hasSrc() ? "Y" : null;
                    } else {
                        return null;
                    }
                }

                public int getWidth(JTable table) {
                    return 50;
                }
            },
            new ColumnInfo<DirNode, Object>("Javadoc") {
                public Object valueOf(DirNode object) {
                    if (object instanceof LibNode) {
                        return ((LibNode)object).hasJavadoc() ? "Y" : null;
                    } else {
                        return null;
                    }
                }

                public int getWidth(JTable table) {
                    return 70;
                }
            },
    };


    public DirNodeTreeTableModel(TreeNode root) {
        super(root, columnInfos);
        getColumnInfos()[0] = new TreeColumnInfo();
    }

    class TreeColumnInfo extends ColumnInfo {
        public TreeColumnInfo() {
            super("Tree");
        }

        public Object valueOf(Object object) {
            return DirNodeTreeTableModel.this;
        }

        public Class getColumnClass() {
            return TreeTableModel.class;
        }

        public int getWidth(JTable table) {
            return 200;
        }
    }
}
